//
//  SearchModel.m
//  万词王
//
//  Created by rimi on 2016/12/6.
//  Copyright © 2016年 dongfumei. All rights reserved.
//

#import "SearchModel.h"

@implementation SearchModel

+ (NSArray<SearchModel *> *)modelsWithArray:(NSArray *)datasource {
    return nil;
}

@end

@implementation IdiomModel

+ (NSArray<SearchModel *> *)modelsWithArray:(NSArray *)datasource {
    
    if (![datasource isKindOfClass:[NSArray class]]) {
        return nil;
    }
    
    NSMutableArray *models = [NSMutableArray array];
    
    [datasource enumerateObjectsUsingBlock:^(NSDictionary *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        IdiomModel *model = [[IdiomModel alloc] init];
        
        [obj enumerateKeysAndObjectsUsingBlock:^(NSString *  _Nonnull key, NSString *  _Nonnull value, BOOL * _Nonnull stop) {
            if ([key isEqualToString:@"id"]) {
                model.wordID = value;
            }else if ([key isEqualToString:@"name"]) {
                model.content = value;
            }
        }];
        
        [models addObject:model];
    }];
    
    return models;
}

@end

@implementation WordModel

+ (NSArray<SearchModel *> *)modelsWithArray:(NSArray *)datasource {
    
    if (![datasource isKindOfClass:[NSArray class]]) {
        return nil;
    }
    
    NSMutableArray *models = [NSMutableArray array];
    
    [datasource enumerateObjectsUsingBlock:^(NSDictionary *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        WordModel *model = [[WordModel alloc] init];
        
        [obj enumerateKeysAndObjectsUsingBlock:^(NSString *  _Nonnull key, NSString *  _Nonnull value, BOOL * _Nonnull stop) {
            if ([key isEqualToString:@"id"]) {
                model.wordID = value;
            }else if ([key isEqualToString:@"hanzi"]) {
                model.content = value;
            }
        }];
        
        [models addObject:model];
    }];
    
    return models;
}

@end

@implementation SingleWordModel

+ (NSArray<SearchModel *> *)modelsWithArray:(NSArray *)datasource {
    
    if (![datasource isKindOfClass:[NSArray class]]) {
        return nil;
    }
    
    NSMutableArray *models = [NSMutableArray array];
    
    [datasource enumerateObjectsUsingBlock:^(NSDictionary *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        SingleWordModel *model = [[SingleWordModel alloc] init];
        
        [obj enumerateKeysAndObjectsUsingBlock:^(NSString *  _Nonnull key, NSString *  _Nonnull value, BOOL * _Nonnull stop) {
             if ([key isEqualToString:@"words"]) {
                model.content = value;
            }
        }];
        
        [models addObject:model];
    }];
    
    return models;
}

@end
